package com.gsta.cdn.cdr.mapper;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.gsta.cdn.cdr.entity.ChannelConcurrent;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Mapper
@Component(value = "ConcurrentMapper")
public interface ConcurrentMapper extends BaseMapper<ChannelConcurrent> {
//    @Select("<script>" +
//            "SELECT Date,ServiceType " +
//            ",sum(hour00) as hour00,sum(hour01) as hour01,sum(hour02) as hour02,sum(hour03) as hour03,sum(hour04) as hour04,sum(hour05) as hour05 " +
//            ",sum(hour06) as hour06,sum(hour07) as hour07,sum(hour08) as hour08,sum(hour09) as hour09,sum(hour10) as hour10,sum(hour11) as hour11 " +
//            ",sum(hour12) as hour12,sum(hour13) as hour13,sum(hour14) as hour14,sum(hour15) as hour15,sum(hour16) as hour16,sum(hour17) as hour17 " +
//            ",sum(hour18) as hour18,sum(hour19) as hour19,sum(hour20) as hour20,sum(hour21) as hour21,sum(hour22) as hour22,sum(hour23) as hour23 " +
//            "FROM ChannelConcurrent " +
//            "WHERE Date = #{Date} " +
//            "GROUP BY ServiceType,Date "+
//            "</script>")
//    List<Map<String, Object>> ChannelConcurrent(@Param("Date") String Date);



    @Select("<script>" +
            "SELECT * FROM ConcurrentAll WHERE Date = #{Date} "+
            "</script>")
    List<Map<String, Object>> ChannelConcurrent(@Param("Date") String Date);


    @Select("<script> " +
            "SELECT Date,'16' as ServiceType  " +
            ",sum(hour00) as hour00,sum(hour01) as hour01,sum(hour02) as hour02,sum(hour03) as hour03,sum(hour04) as hour04,sum(hour05) as hour05 " +
            ",sum(hour06) as hour06,sum(hour07) as hour07,sum(hour08) as hour08,sum(hour09) as hour09,sum(hour10) as hour10,sum(hour11) as hour11 " +
            ",sum(hour12) as hour12,sum(hour13) as hour13,sum(hour14) as hour14,sum(hour15) as hour15,sum(hour16) as hour16,sum(hour17) as hour17 " +
            ",sum(hour18) as hour18,sum(hour19) as hour19,sum(hour20) as hour20,sum(hour21) as hour21,sum(hour22) as hour22,sum(hour23) as hour23 " +
            "FROM VodConcurrent${Date} " +
            "GROUP BY Date "+
//            "SET @SS='VodConcurrent'; " +
//            "SET @tb=CONCAT(@SS,#{Date}); " +
////            "SET @sql = CONCAT('SELECT Date " +
////            ",sum(hour00) as hour00,sum(hour01) as hour01,sum(hour02) as hour02,sum(hour03) as hour03,sum(hour04) as hour04,sum(hour05) as hour05 " +
////            ",sum(hour06) as hour06,sum(hour07) as hour07,sum(hour08) as hour08,sum(hour09) as hour09,sum(hour10) as hour10,sum(hour11) as hour11 " +
////            ",sum(hour12) as hour12,sum(hour13) as hour13,sum(hour14) as hour14,sum(hour15) as hour15,sum(hour16) as hour16,sum(hour17) as hour17 " +
////            ",sum(hour18) as hour18,sum(hour19) as hour19,sum(hour20) as hour20,sum(hour21) as hour21,sum(hour22) as hour22,sum(hour23) as hour23 FROM VodConcurrent' , #{Date}); " +
//////            "WHERE Date = #{Date} " +
//            "PREPARE st FROM @sql; " +
//            "EXECUTE st; " +
//            "DEALLOCATE PREPARE st; "+
            "</script> ")
    List<Map<String, Object>> VodConcurrent(@Param("Date") String Date);



    @Select("<script>" +
            "SELECT DISTINCT Area FROM  ConcurrentArea " +
            " WHERE Date = #{Date} "+
            "</script>")
    List<Map<String, Object>> ConcurrentArea(@Param("Date") String Date);

    @Select("<script>" +
            "SELECT DISTINCT PopName FROM  ConcurrentAreaPopName " +
            " WHERE Date = #{Date} AND Area = #{Area} "+
            "</script>")
    List<Map<String, Object>> ConcurrentAreaPopName(@Param("Date") String Date,@Param("Area") String Area);

    @Select("<script>" +
            " SELECT * FROM ConcurrentArea  " +
            " WHERE Date = #{Date} AND Area = #{Area} "+
            "</script>")
    List<Map<String, Object>> ConcurrentByArea(@Param("Date") String Date,@Param("Area") String Area);

    @Select("<script>" +
            " SELECT * FROM ConcurrentAreaPopName  " +
            " WHERE Date = #{Date} AND Area = #{Area} AND PopName = #{PopName} "+
            "</script>")
    List<Map<String, Object>> ConcurrentByAreaPopName(@Param("Date") String Date,@Param("Area") String Area,@Param("PopName") String PopName);


    @Select("<script>" +
            " SELECT * FROM ConcurrentPopID  " +
            " WHERE Date = #{Date} AND PopID = #{PopID} "+
            "</script>")
    List<Map<String, Object>> ConcurrentByPopID(@Param("Date") String Date,@Param("PopID") String PopID);

    @Select("<script>" +
            " SELECT * FROM ConcurrentPopName  " +
            " WHERE Date = #{Date} AND PopName = #{PopName} "+
            "</script>")
    List<Map<String, Object>> ConcurrentByPopName(@Param("Date") String Date,@Param("PopName") String PopName);

    @Select("<script>" +
            "SELECT DISTINCT PopID FROM  ConcurrentPopID " +
            " WHERE Date = #{Date} "+
            "GROUP BY RAND() LIMIT 30 "+
            "</script>")
    List<Map<String, Object>> ConcurrentPopID(@Param("Date") String Date);


}
